home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr53 / 122_01.zip / TUTORIAL < prev    next >
Text File  |  1993-06-02  |  13KB  |  418 lines

  1. TUTORIAL (headings are approximate):
  2. copyright (C) 1983 by E. E. Bergmann
  3. General, the prompt and stack.
  4. Using memory, constants and variables.
  5. Simple i/o, defining new words.
  6. Iteration and conditional.
  7. Numerical i/o.
  8. Redefining and FORGET.
  9. The editor.
  10. ::
  11. :::
  12. *********************************************************
  13. *                            *
  14. * PISTOL-Portably Implemented Stack Oriented Language    *
  15. *            Version 2.0            *
  16. * (C) 1983 by    Ernest E. Bergmann            *
  17. *        Physics, Building #16            *
  18. *        Lehigh Univerisity            *
  19. *        Bethlehem, Pa. 18015            *
  20. *                            *
  21. * Permission is hereby granted for all reproduction and *
  22. * distribution of this material provided this notice is *
  23. * included.                        *
  24. *                            *
  25. *********************************************************
  26. ::
  27. :::
  28. [A carriage return will continue the scroll;
  29. a "Q" and then a carriage return will abort]
  30.     Before discussing some examples and features, it is
  31. probably best to understand the "prompt".  The prompt is what a
  32. program types at the beginning of the line when it is awaiting
  33. input from the user.  The prompt supplied by PISTOL can be
  34. several characters long and it is to inform or remind the user
  35. about the "state" of the program.  If a number appears at the
  36. beginning of the prompt, it signifies that the parameter stack
  37. is not empty.  Next, a letter is displayed (such as "X") that
  38. indicates the current number base used for i/o ("X", the Roman
  39. numeral for "10", signifies decimal). After this letter there
  40. may be other characters or symbols that are used to indicate if
  41. you are in the middle of some syntactical construction.
  42. Finally, the ">" completes the prompt expression.  In the
  43. examples supplied above and below we have attempted to suggest
  44. the typical prompts that one might expect to see.
  45.  
  46.     After educating PISTOL by loading PBASE2 or by
  47. restoring CORE2, the system is "smarter" you can try the
  48. following examples:
  49.  
  50. X> 1 2 23 STACK
  51.  
  52. The system takes each number as encountered and places them on
  53. the stack.  The word, STACK , prints the current contents of
  54. the stack without changing the stack in any way.
  55.  
  56.     Now try typing:
  57. 3X> + STACK
  58.  
  59. This should result in the addition of the top two members of
  60. the stack (2 and 23) and placing the result (answer 25) back on
  61. the stack. The word STACK then displays the current contents of
  62. the stack.
  63.  
  64.     Now try typing:
  65. 2X> * stack
  66.  
  67. The top two items of the stack will be multiplied together and
  68. the result left on the stack.  The word, "stack" is interpreted
  69. as STACK, and we see that the only thing on the stack is the
  70. answer 25.
  71.  
  72.     To disable the automatic interpretation of lowercase
  73. as uppercase, type:
  74.  
  75. X> RAISE OFF (or "raise off")
  76.  
  77. and successive lines will be interpreted without conversion of
  78. lowercase to uppercase.  To revert to conversion, type:
  79.  
  80. X> RAISE ON
  81.  
  82.     There are a number of different options that can be
  83. invoked such as ECHO ON and ECHO OFF which control the listing
  84. of files read in by the '<filename> LOAD operation.  One can
  85. use CONSOLE ON and CONSOLE OFF to determine what reaches the
  86. terminal.  An error condion will automatically restore output
  87. to the terminal.  LIST ON and LIST OFF will determine what
  88. output will also be routed to the output list file(of course a
  89. listfile has to be declared first).  This is useful to have a
  90. more permanent record of what happened during a session.  There
  91. is also a SHOWCODE and a NOSHOWCODE which will show the results
  92. of compiling each input line (that is for those who want or
  93. like to know what is going on behind the scenes).
  94.  
  95.     On the DEC-20 (and also in CP/M) one can exit from
  96. PISTOL by using a control-C, but a more "refined" way is to
  97. type the word, BYE, which will return you to the operating
  98. system.
  99. ::
  100. :::
  101.     PISTOL can examine the contents of its own (virtual)
  102. memory. The W@ ("fetch") operator is similar in spirit to
  103. the PEEK function in BASIC.  To place the contents of a
  104. memory location on the stack one simply places the address
  105. on stack and then types W@ .  For example, if we want to
  106. place on the stack the current value of RADIX, the base used
  107. in all I/O number conversion, we need to find the value
  108. stored in the RAM location at USER (i.e. what is RAM[USER]?)
  109. we can type:
  110.  
  111. X> USER W@
  112.  
  113. which will place the desired information on stack.  The inverse
  114. operation, which is more dangerous(because a mistake can crash
  115. the program), is to store a new value in the RADIX, hence
  116. change the number base.  The operator, W! ("word store"),
  117. performs this function(for this example we suppose that the
  118. RADIX address is 12345 decimal, usually, it is not):
  119.  
  120. X> 16 12345 W!
  121.  
  122. would convert PISTOL to converse in hexadecimal.
  123.  
  124.     Of course it is awkward to remember constants, such
  125. as the address of RADIX so we can define such constants by:
  126.  
  127.  > DECIMAL
  128. X> 12345 'RADIX CONSTANT
  129.  
  130. After such a CONSTANT definition we can redo the examples that
  131. use W@ and W! by (RADIX is in fact already defined in PBASE2):
  132.  
  133. X> RADIX W@
  134. and
  135. X> 16 RADIX W!
  136.  
  137.     As an additional convenience the user can define space
  138. for variables with the word, VARIABLE.  For example, If you
  139. wish to define a variable with the initial value 0 and named
  140. ANSWER, you should type:
  141.  
  142. X> 0 'ANSWER VARIABLE
  143.  
  144. Later, if you wish to perform the PASCAL statement:
  145.  
  146. ANSWER := ANSWER + 1;
  147.  
  148. you would write the PISTOL code:
  149.  
  150. X> ANSWER W@ 1 + ANSWER W!
  151.  
  152. Notice that you MUST choose an initial value in VARIABLE and,
  153. of course, CONSTANT definitions.
  154.  
  155.     Just like the convenience feature of PASCAL,
  156. for which one can use SUCC(ANSWER) to increment ANSWER
  157. by one, there exists an analogous operator (or you can
  158. define your own!):
  159.  
  160. X> ANSWER 1+W!
  161.  
  162. ::
  163. :::
  164.     The language has many resources beyond those
  165. presented so far.  Perhaps the most significant is the
  166. ability to define new words or definitions to make the
  167. language increasingly smarter. Try examining the contents of
  168. the file, PBASE2 , to see how the definitions may be formed.
  169. As a complex example, the word, = is defined whose function
  170. is to take the top item off of the stack and print its
  171. value.  For example, typing:
  172.  
  173. X> 8 8 + =
  174.  
  175. will cause the system to respond with the answer: 16.  Note
  176. that this calculation causes no net change to the stack (it
  177. is the presence of a number before "X>" that indicates the
  178. number of items in the stack at that moment); its contents
  179. before the first "8" was typed is the same as its contents
  180. after the system responds with 16.  Thus the definition of
  181. the word = has increased the convenience of the system for
  182. arithmetic calculations.
  183.  
  184.     The system can and does handle strings.  Suppose you
  185. would like the system to output "HELLO".  Try typing:
  186.  
  187. X> 'HELLO MSG
  188.  
  189. The system will take the 'HELLO as a string to be placed upon
  190. the stack.  The MSG ,"message" takes the top item off of the
  191. stack, assumes it to be a string, and prints it.  The stack
  192. contains the same stuff after MSG is executed as before the
  193. 'HELLO was typed.
  194.  
  195.     Useful I/O words are CR which will output a carriage
  196. return and line feed sequence.  The word SPACE will output a
  197. space. And the word SPACES will pop the top of stack to obtain
  198. the number of spaces to be output.  For example:
  199.  
  200. X> 'HELLO MSG SPACE 'HELLO MSG CR 5 SPACES 'BYE MSG
  201.  
  202. should produce:
  203.  
  204. HELLO HELLO
  205.      BYE
  206.  
  207.  
  208.     Standard output would be most tedious if we could not
  209. create definitions to speed up programming.  Here is a humorous
  210. example:
  211.  
  212. X> 'HELLO : 'HELLO, MSG SPACE 'YOURSELF! CR ;
  213.  
  214. The use of : and ; provide the means to define a new word
  215. "HELLO" Later, you can type:
  216.  
  217. X> HELLO
  218.  
  219. and the system will respond:
  220.  
  221. HELLO, YOURSELF!
  222.  
  223.     Thus we see that the pair of symbols, ":" and ";"
  224. delineate a structure used to make definitions.  The material
  225. in between the two symbols becomes the definition of the word
  226. whose name is the string that was lastly placed on the stack
  227. before the ":".
  228.  
  229.     One can create strings with embedded blanks and tabs up
  230. to 127 characters long by using double quotes to delineate both
  231. ends of the string.  For example, the word, HELLO, defined
  232. above, could have been defined:
  233.  
  234. 'HELLO : "HELLO, YOURSELF!" MSG CR ;
  235.  
  236. Even with RAISE ON, lowercase characters within double
  237. quotation marks will not be converted.
  238.  
  239. ::
  240. :::
  241.     There are other types of structures.  The pair of
  242. words, DO and LOOP permit an iterative structure.  They use the
  243. top two quantities on the stack as limits of iteration.  So:
  244.  
  245. X> nn n DO ... LOOP
  246.  
  247. is equivalent to the PASCAL structure:
  248.  
  249.     FOR  I := n TO (nn-1) DO
  250.         BEGIN ... END;
  251.  
  252. To place the current value of the iteration variable on the
  253. stack one uses the word, "I" .  Here is an example that you can
  254. try:
  255.  
  256. X> 'COUNTING : CR 1 + 1 DO I = SPACE LOOP ;
  257.  
  258. X> 10 COUNTING
  259. and see PISTOL counting to 10.
  260.  
  261.     An alternative terminating word to this structure is
  262. +LOOP.  If one uses in PISTOL:
  263.  
  264.     nn n DO ... m +LOOP
  265. one simulates the BASIC structure:
  266.  
  267. 100 FOR I=n TO (nn-1) STEP m
  268. .
  269. .
  270. .
  271. 200 NEXT I
  272.  
  273.     PISTOL supports a conditional structure of the form:
  274.  
  275.     IF ... ELSE .... THEN
  276.  
  277. When the IF is encountered the top of the stack is used as a
  278. boolean variable; it is considered false if equal to zero and
  279. true otherwise (as in LISP).  If true, the actions "..." that
  280. are bracketed between IF and ELSE are carried out; then program
  281. flow skips to what follows THEN.  Whereas, if the top of the
  282. stack was false, the actions "...." between ELSE and THEN are
  283. carried out instead. The "ELSE ...." portion is optional, in
  284. analogy to PASCAL.
  285.  
  286.     To illustrate, here is an example:
  287.  
  288. X> 'STATE? :
  289. X:> 'TURNED- MSG W@ IF 'ON ELSE 'OFF THEN
  290. 1X:> MSG ;
  291. X>
  292.  
  293. Trying this new word:
  294.  
  295. X> CONSOLE STATE?
  296. we get the response:
  297. TURNED-ON
  298.  
  299. whereas for:
  300.  
  301. X> LIST STATE?
  302. TURNED-OFF
  303.  
  304.     PISTOL supports a number of other structures which are
  305. analogous to the PASCAL structures:
  306.  
  307.         WHILE .. DO ... ;
  308.  
  309.             and
  310.  
  311.         REPEAT ... UNTIL NOT .. ;
  312.  
  313. They are, respectively:
  314.  
  315.         BEGIN .. IF ... REPEAT
  316.  
  317.             and
  318.  
  319.         BEGIN ... .. END
  320.  
  321.     As in most languages, structures may be nested.  In the
  322. interest of user convenience, the prompt will indicate whether
  323. execution is being deferred, pending completion of unfinished
  324. structures.
  325. ::
  326. :::
  327.     PISTOL can communicate in a variety of different number
  328. bases, as was alluded to in the section on W@ and W! . Changing
  329. bases has been formalized by a set of defined words provided in
  330. PBASE2.  These words are: BINARY(B), OCTAL(Q), DECIMAL(X), and
  331. HEX(H); the parenthesized letter is the corresponding symbol
  332. that appears in the prompt.  Thus, in the examples described
  333. above, the number base was decimal.  Here are a few examples of
  334. the use of other number bases:
  335.  
  336. X> HEX
  337. H> 8 8 + =
  338. 10
  339. H> 11 BINARY =
  340. 10001
  341. B> 2
  342. 2 ?
  343. ***PISTOL 2.0***
  344.  
  345. B>
  346.     Whenever the system responds with ***PISTOL 2.0*** it
  347. has performed an ABORT which resets stacks and prints this
  348. identifying message.
  349. ::
  350. :::
  351.     You may "redefine" words, that is to say, the same name
  352. may be used again and again.  Earlier definitions that use the
  353. word will continue to utilize the old meaning; future defini-
  354. tions that reference the redefined word will access the new
  355. meaning.  A warning will be issued when you are redefining.
  356.  
  357.     It is important to keep in mind that when new words are
  358. defined, their names are added to the "string stack" and the
  359. compiled code is added to the "code stack".  If a recent
  360. definition is not satisfactory, or no longer serves a need, you
  361. may wish to "FORGET" it, so that the "string stack" and the
  362. "code stack" are popped of this useless material.  To discard
  363. this definition AND ALL SUBSEQUENT DEFINITIONS, one should
  364. type:
  365.  
  366. X> '<name> FORGET
  367.  
  368.     To obtain the code locations and names of the last ten
  369. definitions, type:
  370.  
  371. X> TOP10
  372.  
  373. To obtain information successively on the ten previous
  374. definitions, type:
  375.  
  376. 1X> NEXT10
  377.  
  378. ::
  379. :::
  380.     A crude, line-oriented editor has been implemented
  381. inside PISTOL.  Try it out by typing the following sequence
  382. of commands:
  383.  
  384. X> LI
  385.  
  386. X> 3 LI
  387.  
  388. X> 3 5 LI
  389.  
  390. X> 4 2 LI
  391.  
  392. X> 3 INPUT
  393. 3: MARY HAD
  394. 4: A LITTLE
  395. 5: LAMB.
  396. 6: <cr>
  397.  
  398.  
  399. X> LI
  400.  
  401. X> 3 DELETE
  402.  
  403. X> LI
  404.  
  405.     It is possible to test definitions or other commands
  406. while they are still in the edit buffer.  Make sure that the
  407. edit buffer has the word: ;F at the end ot the section that
  408. you wish to test (it acts as a logical end-of-file).
  409. Determine the line number of the portion where you wish to
  410. start the test, say it is line 14.  All you need to type is:
  411.  
  412. X> 14 LOAD
  413.  
  414. This degree of interaction should appeal to those who like 
  415. BASIC!?
  416. :
  417. less material.  To discard
  418. this de